#include"Binary_tree.h"

template<class Entry>
Binary_tree<Entry>::Binary_tree()
{
	root == NULL;
}

template<class Entry>
bool Binary_tree<Entry>::empty()const
{
	return root == NULL;
}

template<class Entry>
void Binary_tree<Entry>::inorder(void (*visit)(Entry&)) 
{
	recursive_inorder(root, visit);
}

template<class Entry>
void Binary_tree<Entry>::preorder(void (*visit)(Entry&))
{
	recursive_preorder(root, visit);
}

template<class Entry>
void Binary_tree<Entry>::postorder(void (*visit)(Entry&))
{
	recursive_postorder(root, visit);
}

template<class Entry>
void Binary_tree<Entry>::recursive_inorder(Binary_node<Entry>* sub_root, void (*visit)(Entry&))
{
	if (sub_root != NULL)
	{
		recursive_inorder(sub_root->left, visit);
		(*visit)(sub_root->data);
		recursive_inorder(sub_root->right, visit);
	}
}

template<class Entry>
void Binary_tree<Entry>::recursive_preorder(Binary_node<Entry>* sub_root, void (*visit)(Entry&))
{
	if (sub_root != NULL)
	{
		recursive_preorder(sub_root->left, visit);
		(*visit)(sub_root->data);
		recursive_preorder(sub_root->right, visit);
	}
}

template<class Entry>
void Binary_tree<Entry>::recursive_postorder(Binary_node<Entry>* sub_root, void (*visit)(Entry&))
{
	if (sub_root != NULL)
	{
		recursive_postorder(sub_root->left, visit);
		(*visit)(sub_root->data);
		recursive_postorder(sub_root->right, visit);
	}
}